<?php
namespace app\wechat\controller;

use app\common\base\BasicRest;
use app\wechat\model\UserInfoModel;
use think\Config;
use think\Db;
use think\Request;
use think\Session;

class Qiandao extends  BasicRest
{


    protected $beforeActionList = [
          'islogin'
      ];

    public function __construct()
    {
        parent::__construct();
    }
    //判断是否登陆
    protected function islogin(){
        if(!Session::has('userid')){
            return $this->redirect('/php/public/wechat/login/login',302);
        }
    }
        

   public function qiandao(){
        $user=UserInfoModel::get(Session::get('userid'));
        if($user){
            //已经签到了
            if($user->is_check==1){
                return $this->redirect('/php/public/wechat/choujiang/choujiang',302);
            }
            return $this->fetch('qiandao');
        }
        return $this->redirect('/php/public/wechat/login/login',302);

   }

   public function qiandaosuccess(){
         $data=$this->request->post();
        if(!empty($data['quxian'])&&!empty($data['shenfen'])&&!empty($data['name'])){
             $user=UserInfoModel::get(Session::get('userid'));
             if($user['is_check']==1){
                return res_fail(['ret'=>2,'msg'=>'该用户已经签到']);
             }
             $user->name=$data['name'];
             $user->identity=$data['shenfen'];
             $user->county=$data['quxian'];
             $user->is_check=1;
             if($user->save()){
                return res_success(['ret'=>1]);
             }
             return res_fail('签到失败');
        }
   }
  
}